/**
 * Copyright &copy; 2013-2015 山东易科德软件有限公司   All rights reserved.
 */
package cn.net.ecode.modules.sys.entity;

import org.apache.commons.lang3.StringUtils;
import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.NotBlank;

import cn.net.ecode.common.persistence.DataEntity;
import cn.net.ecode.common.persistence.annotation.Id;

/**
 * 模块管理Entity
 * @author ThinkGem
 * @version 2014-8-19
 */
public class Module extends DataEntity<Module> {
	
	private static final long serialVersionUID = 1L;
	private String moduleCode;		// 编码
	private String moduleName;		// 名称
	private String description;		// 描述
	private String className;		// 核心类名称
	
	public Module() {
		super();
	}

	public Module(String id){
		super(id);
	}
	
	@Id
	public String getModuleCode() {
		return moduleCode;
	}

	public void setModuleCode(String moduleCode) {
		this.moduleCode = moduleCode;
	}

	@NotBlank(message="名称不能为空")
	@Length(min=0, max=100, message="名称长度不能超过 100 个字符")
	public String getModuleName() {
		return moduleName;
	}

	public void setModuleName(String moduleName) {
		this.moduleName = moduleName;
	}
	
	@Length(min=0, max=100, message="描述长度不能超过 2000 个字符")
	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getClassName() {
		return className;
	}

	public void setClassName(String className) {
		this.className = className;
	}
	
	/**
	 * 模块是否加载
	 * @return
	 */
	public Boolean getIsLoader(){
		try {
			if (StringUtils.isNotBlank(className)){
				return Class.forName(className) != null;
			}
			return false;
		} catch (ClassNotFoundException e) {
			return false;
		}
	}
	
	/**
	 * 模块是否启用
	 * @return
	 */
	public Boolean getIsEnable(){
		return getIsLoader() && STATUS_NORMAL.equals(status);
	}
	
}